package cn.ronghuanet.base.exception;

/**
 * 定义自定义异常,也就是业务异常
 * 自定义异常类,就是写一个普通类继承RunTimeException,重写它的构造方法就可以了
 */
public class BusinessException extends RuntimeException{

    private Integer code;

    public BusinessException() {
        super();
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    protected BusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    /**
     * 当别人使用ResponseCode作为参数传递进来的时候,将ResponseCode的code赋值给当前异常类的code,将它的message用来调用父类的方法
     * @param responseCode
     */
    public BusinessException(ResponseCode responseCode){
        super(responseCode.getMessage());
        // 给当前类的code赋值为ResponseCode里面的code的值
        this.code = responseCode.getCode();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
